package com.zhyt.intelligentpipeline.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhyt.intelligentpipeline.mapper.*;
import com.zhyt.intelligentpipeline.model.*;
import com.zhyt.intelligentpipeline.service.StationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class StationServiceImpl implements StationService {

    @Resource
    private StationMapper stationMapper;

    @Resource
    private GasComponentMapper gasComponentMapper;

    @Resource
    private SupplyGasMapper supplyGasMapper;

    @Resource
    private IntakeGasMapper intakeGasMapper;

    @Resource
    private TransferPressureMapper transferPressureMapper;

    @Override
    public Station getStationByName(String name) {
        QueryWrapper<Station> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Station::getName,name);
        return stationMapper.selectOne(queryWrapper);
    }

    @Override
    public GasComponent getStationGasComponent(Date date,String stationName) {
        QueryWrapper<GasComponent> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(GasComponent::getDate,date).eq(GasComponent::getStationName,stationName);
        return gasComponentMapper.selectOne(queryWrapper);
    }

    @Override
    public List<SupplyGas> getStationSupplyGasVolume(Date date, String stationName) {
        QueryWrapper<SupplyGas> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplyGas::getDate,date).eq(SupplyGas::getSupplySite,stationName);
        return supplyGasMapper.selectList(queryWrapper);
    }

    @Override
    public IntakeGas getStationIntake(Date date,  String intakeSite) {
        QueryWrapper<IntakeGas> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(IntakeGas::getDate,date).eq(IntakeGas::getIntakeSite,intakeSite);
        return intakeGasMapper.selectOne(queryWrapper);
    }

    @Override
    public TransferPressure getStationTransPressure(Date date, String stationName) {
        QueryWrapper<TransferPressure> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TransferPressure::getDate,date).eq(TransferPressure::getStationName,stationName);
        return transferPressureMapper.selectOne(queryWrapper);
    }
}
